package com.team8.system.service.controller;

import com.team8.system.pojo.DicCode;
import com.team8.system.service.service.DicCodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Controller
@RequestMapping("/diccode")
public class DicCodeController {

    @Autowired
    private DicCodeService dicCodeService;

    @RequestMapping("/selectDicCode")
    public ResponseEntity<List<DicCode>> selectDicCode(
            @RequestParam("tcc") String tcc,
            @RequestParam("fcc") String fcc,
            @RequestParam("name") String name){

        List<DicCode> dicCodes = dicCodeService.selectDicCodeService(tcc, fcc, name);

        return ResponseEntity.ok(dicCodes);

    }

    @RequestMapping("/selectDicCodeByTcc")
    public ResponseEntity<List<DicCode>> selectDicCodeByTcc(
            @RequestParam("tcc") String tcc){

        List<DicCode> dicCodes = dicCodeService.selectDicCodeService(tcc);
        if(!CollectionUtils.isEmpty(dicCodes))
            return ResponseEntity.ok(dicCodes);
        return null;
    }

  @RequestMapping("/selectDicCodeByName")
    public ResponseEntity<List<DicCode>> selectDicCodeByName(
            @RequestParam("name") String name){

      List<DicCode> dicCodes = dicCodeService.selectDicCodeService("", "", name);

        return ResponseEntity.ok(dicCodes);

    }


    @RequestMapping("/selecAlltDicCode")
    public ResponseEntity<List<DicCode>> selecAlltDicCode(){

        List<DicCode> dicCodes = dicCodeService.selecAlltDicCode();

        return ResponseEntity.ok(dicCodes);

    }

}
